import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'

// Setup Store写法
export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const obj = reactive({
    age: 18
  })
  const arr = reactive([1, 2, 3, 4, 5, 6])
  const add5 = computed(() => {
    return obj.age + 5
  })

  const add = () => {
    count.value++
  }
  return { count, obj, add5, add, arr }
})

// Option Store写法

export const userOptionStore = defineStore('Option', {
  state() {
    return {
      use: {
        name: 'zp',
        age: 18
      }
    }
  },
  getters: {
    ageadd5(state) {
      return state.use.age + 20
    }
  },
  actions: {
    ageadd(event) {
      console.log(event)
      this.use.age++
    }
  }
})